package hesso.smartdraw.ch.model;

import java.util.ArrayList;
import java.util.Arrays;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

public class Room implements Parcelable{

	private int id = 0;
	private String name = "default";
	private ArrayList<Wall> walls = new ArrayList<Wall>();
	
	public Room(int id, String name){
		this.id = id;
		this.name = name;
	}
	
	public Room(String name){
		this.name = name;
	}
	
	public Room(){
		this("unnamed Room");
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public ArrayList<Wall> getWallArray() {
		return walls;
	}

	public void setWallArray(ArrayList<Wall> walls) {
		this.walls = walls;
	}

	public void addWall(Wall wall) {
		this.walls.add(wall);
	}
	
	public void removeWall(Wall wall) {
		this.walls.remove(wall);
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
    	Log.d("tryout", "write Room Parcel");
		dest.writeInt(id);
		dest.writeString(name);
		dest.writeParcelableArray(walls.toArray(new Wall[walls.size()]), 0);
    	Log.d("tryout", "Room Parcel written");
	}
	
	public static final Parcelable.Creator<Room> CREATOR = new Parcelable.Creator<Room>() {
		@Override
		public Room createFromParcel(Parcel source) {
			// TODO Auto-generated method stub
			return new Room(source);
		}

		@Override
		public Room[] newArray(int size) {
			// TODO Auto-generated method stub
			return new Room[size];
		}		
	};
	
	private Room(final Parcel in){
		readFromParcel(in);
	}
	
	public void readFromParcel(final Parcel in){
    	Log.d("tryout", "read from Room Parcel");
		id = in.readInt();		
		name = in.readString();
		walls = (ArrayList<Wall>)Arrays.asList((Wall[])in.readArray(ClassLoader.getSystemClassLoader()));
	}
}